package manager

import (
	"fmt"
	"server/common"
	"server/pkg/app"
)

type CasbinRule struct {
	Type string `gorm:"column:group;type:varchar(100);" json:"ptype"`
	Obj  string `gorm:"column:v0;type:varchar(100);" json:"sub"`
	V1   string `gorm:"column:v1;type:varchar(100);" json:"obj"`
	V2   string `gorm:"column:v2;type:varchar(100);" json:"act"`
	ID   int64  `gorm:"column:id;type:bigint(20);" json:"id"`
}

func (c *CasbinRule) TableName() string {
	return "casbin_rule"
}

func (casbin *CasbinRule) List(page *app.Page) ([]CasbinRule, int64) {
	casbins := []CasbinRule{}
	var count int64
	if err := common.CasbinDB.Debug().Order("id desc").Limit(page.Size).Offset((page.Page - 1) * page.Size).Find(&casbins).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
		return casbins, count
	}
	fmt.Println(casbins)
	return casbins, count
}
